package com.tfswx.jcyw.sqlmodel.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.tfswx.jcyw.sqlmodel.api.bean.table.*;
import com.tfswx.jcyw.sqlmodel.api.bean.table.expression.*;

import java.io.IOException;

/**
 * @author 张述江
 * @date 2023/9/15
 */
public class A_Test {
    public static void main(String[] args) {
        PlainSelect select1 = new PlainSelect();
        select1.addSelectItem(new SelectItem(new Column("部门受案号"), "部门受案号"));
        select1.addSelectItem(new SelectItem(new Column("姓名"), "姓名"));
        select1.addSelectItem(new SelectItem(new Column("年龄"), "年龄"));
        select1.addSelectItem(new SelectItem(new Column("证件号码"), "证件号码"));
        select1.addSelectItem(new SelectItem(new Column("案由"), "案由"));
        select1.addSelectItem(new SelectItem(new Column("一审宣告刑"), "一审宣告刑"));
        select1.addSelectItem(new SelectItem(new Column("一审附加刑"), "一审附加刑"));
        select1.addSelectItem(new SelectItem(new Column("宣告刑刑期"), "宣告刑刑期"));
        select1.addSelectItem(new SelectItem(new Column("刑期年"), "刑期年"));
        select1.addSelectItem(new SelectItem(new Column("刑期月"), "刑期月"));
        select1.addSelectItem(new SelectItem(new Column("刑期天"), "刑期天"));
        select1.addSelectItem(new SelectItem(new Column("罚金数额"), "罚金数额"));
        select1.addSelectItem(new SelectItem(new Column("审定数额"), "审定数额"));
        select1.addSelectItem(new SelectItem(new Column("缓刑考验期"), "缓刑考验期"));
        select1.addSelectItem(new SelectItem(new Column("缓刑年"), "缓刑年"));
        select1.addSelectItem(new SelectItem(new Column("缓刑月"), "缓刑月"));
        select1.addSelectItem(new SelectItem(new Column("缓刑天"), "缓刑天"));
        select1.setFromItem(new TableFromItem("t_sr_02f6f34c6ecc4ed5a514a2fa7fe4017d"));


        PlainSelect select2 = new PlainSelect(new ParenthesedSelect(select1));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.部门受案号"), "部门受案号"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.姓名"), "姓名"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.年龄"), "年龄"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.证件号码"), "证件号码"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.案由"), "案由"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.一审宣告刑"), "一审宣告刑"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.一审附加刑"), "一审附加刑"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.宣告刑刑期"), "宣告刑刑期"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.刑期年"), "刑期年"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.刑期月"), "刑期月"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.刑期天"), "刑期天"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.罚金数额"), "罚金数额"));
        select2.addSelectItem(new SelectItem(new Column("wjsra1142.审定数额"), "审定数额"));


        WhereItem whereItemList = new WhereItem(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("危险驾驶罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("非法吸收公共存款罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("集资诈骗罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("信用卡诈骗罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("合同诈骗罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("抢劫罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("盗窃罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("诈骗罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("抢夺罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("敲诈勒索罪")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("掩饰")));
        whereItemList.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("掩饰、隐瞒犯罪所得、犯罪所得收益罪")));
        whereItemList.andWhere(new EqualsTo(new Column("wjsra1142.一审附加刑"), new StringValue("罚金")));
        whereItemList.andWhere(new MinorThan(new Column("wjsra1142.年龄"), new StringValue("18")));

        WhereItem whereItemList1 = new WhereItem(whereItemList);
        whereItemList1.andWhere(new MinorThan(new Function("tofloat64ornull", new Column("wjsra1142.罚金数额")), new Function("tofloat64ornull", new StringValue("0.05"))));

        select2.setWhere(whereItemList1);

        PlainSelect select3 = new PlainSelect(new ParenthesedSelect(select1));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.部门受案号"), "部门受案号"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.姓名"), "姓名"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.年龄"), "年龄"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.证件号码"), "证件号码"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.案由"), "案由"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.一审宣告刑"), "一审宣告刑"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.一审附加刑"), "一审附加刑"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.宣告刑刑期"), "宣告刑刑期"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.刑期年"), "刑期年"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.刑期月"), "刑期月"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.刑期天"), "刑期天"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.罚金数额"), "罚金数额"));
        select3.addSelectItem(new SelectItem(new Column("wjsra1142.审定数额"), "审定数额"));


        WhereItem whereItemList2 = new WhereItem(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("危险驾驶罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("非法吸收公共存款罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("集资诈骗罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("信用卡诈骗罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("合同诈骗罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("抢劫罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("盗窃罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("诈骗罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("抢夺罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("敲诈勒索罪")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("掩饰")));
        whereItemList2.andWhere(new NotEqualsTo(new Column("wjsra1142.案由"), new StringValue("掩饰、隐瞒犯罪所得、犯罪所得收益罪")));
        whereItemList2.andWhere(new EqualsTo(new Column("wjsra1142.一审附加刑"), new StringValue("罚金")));
        whereItemList2.andWhere(new GreaterThanEquals(new Column("wjsra1142.年龄"), new StringValue("18")));

        WhereItem whereItemList3 = new WhereItem(whereItemList2);
        whereItemList3.andWhere(new MinorThan(new Function("tofloat64ornull", new Column("wjsra1142.罚金数额")), new Function("tofloat64ornull", new StringValue("0.1"))));

        select3.setWhere(whereItemList3);

        SetOperationList select4 = new SetOperationList(select2);
        select4.addSelect(new UnionOperation(true, false), select3);

        PlainSelect select5 = new PlainSelect(new ParenthesedSelect(select4));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.部门受案号"), "部门受案号"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.姓名"), "姓名"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.年龄"), "年龄"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.证件号码"), "证件号码"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.案由"), "案由"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.一审宣告刑"), "一审宣告刑"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.一审附加刑"), "一审附加刑"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.宣告刑刑期"), "宣告刑刑期"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.罚金数额"), "罚金数额"));
        select5.addSelectItem(new SelectItem(new Column("sjhbf9e7d.审定数额"), "审定数额"));


        String jsonString = Select.toJson(select5);
        System.out.println(jsonString);
        Select select5_tmp = Select.fromJson(jsonString);
        System.out.println("==================");
        System.out.println(select5);
        System.out.println(select5_tmp);
        System.out.println(String.valueOf(select5_tmp).equals(select5.toString()));
    }
}
